Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Saves computed styles in the state #9176

Merged
merged 1 commit into from
Jun 16, 2017

Conversation

NejcZdovc
Copy link
Contributor

@NejcZdovc NejcZdovc commented May 31, 2017

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).

Resolves #9149

Auditors: @bsclifton @bridiver

Test Plan:

Reviewer Checklist:

Tests

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

@NejcZdovc NejcZdovc added this to the 0.18.x milestone May 31, 2017
@NejcZdovc NejcZdovc self-assigned this May 31, 2017
@NejcZdovc NejcZdovc requested review from bridiver and bsclifton and removed request for bridiver and bsclifton May 31, 2017 16:40
@NejcZdovc NejcZdovc force-pushed the refactor/#9149-computed branch from 3e4eabf to 451cf04 Compare June 1, 2017 17:07
@@ -93,11 +96,14 @@ class Window extends React.Component {

componentDidMount () {
appActions.windowReady(getCurrentWindowId())
this.updateComputedStyles()
window.addEventListener('resize', this.updateComputedStyles)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have a window resize handler in windows.js that triggers appActions.windowUpdated and it is debounced to prevent a flood of actions during resize. I think it would be better to send that action to the window using queryInfo (see urlBarTextChanged for an example) and update the computed styles in response to that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -45,6 +47,7 @@ class Window extends React.Component {

this.onChange = this.onChange.bind(this)
this.onAppStateChange = this.onAppStateChange.bind(this)
this.updateComputedStyles = throttle(this.updateComputedStyles.bind(this), 66)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of this and rely on the existing windowUpdated debounce

Copy link
Contributor Author

@NejcZdovc NejcZdovc Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into windows.js

@@ -1411,6 +1411,14 @@ const appActions = {
dispatch({
actionType: appConstants.APP_UPDATE_LOG_OPENED
})
},

updateComputedStyles: function (windowId, values) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should actually be in windowActions. We are generally moving away from windowActions and appActions, but we will keep windowActions for actions that are related to the window component. It can still be handled in the browser process

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also should be declarative updateComputedStyles -> computedStylesChanged or something similar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -148,6 +148,13 @@ const api = {
return state.set('windows', windows.delete(index).insert(index, windowValue))
},

updateComputedStyles: (state, action) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think setComputedStyles and we are moving away from passing actions into state helpers so I think this should take windowId and computedStyles

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return result
}

const getComputedProperty = (state, property) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be replaced by a getComputedStyles method in windowState. We don't want anything outside of windowState to be tightly coupled to the storage path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved

@bridiver
Copy link
Collaborator

bridiver commented Jun 7, 2017

I like the general idea, just needs some tweaks

@NejcZdovc NejcZdovc force-pushed the refactor/#9149-computed branch 5 times, most recently from dae69f6 to a4213bc Compare June 13, 2017 12:29
appActions.windowUpdated(windowValue)
updateComputedStyles(win)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem with calling this function from this file is that we don't have document, so you can't do document.querySelector. Any idea how to fix this? @bridiver

@NejcZdovc NejcZdovc force-pushed the refactor/#9149-computed branch from a4213bc to bf7c248 Compare June 13, 2017 15:49
@NejcZdovc NejcZdovc modified the milestones: 0.19.x (Nightly Channel), 0.18.x (Developer Channel) Jun 13, 2017
@NejcZdovc
Copy link
Contributor Author

@bridiver can you please checkout my review comment

@NejcZdovc NejcZdovc force-pushed the refactor/#9149-computed branch 2 times, most recently from ca1a1a1 to 44c65ae Compare June 15, 2017 21:31
@NejcZdovc NejcZdovc requested a review from bridiver June 15, 2017 21:31
this.chevronWidth = this.chevronMargin + Number.parseInt(this.fontSize)
}
this.maxWidth = windowsUtil.getCSSElementProperty('bookmark-item-max-width')
this.padding = windowsUtil.getCSSElementProperty('--bookmark-item-padding') * 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these shouldn't have dashes, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. Fixed

@NejcZdovc NejcZdovc force-pushed the refactor/#9149-computed branch from 44c65ae to c1cfe7e Compare June 15, 2017 21:45
@NejcZdovc NejcZdovc requested a review from bridiver June 15, 2017 21:46
Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, maybe just some naming changes

* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const computedStyles = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this go under renderer now instead of common?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

computed also probably doesn't make sense anymore since these are static values

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, almost forgot. We should comment this file and the less files to make sure they don't get out-of-sync

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't want anyone to think they can only update one or the other

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would leave it here, because we have all constants files here and this are constants

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added

return Immutable.fromJS({
location: site.get('location'),
order: site.get('order'),
partitionNumber: site.get('partitionNumber') || 0
})
}

const getCSSElementProperty = (prop) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe renderer/styleUtil ? getStyleValue ?

@NejcZdovc NejcZdovc force-pushed the refactor/#9149-computed branch 2 times, most recently from cd4775a to 2c1c1be Compare June 15, 2017 22:09
@bridiver
Copy link
Collaborator

please add comments to styleValues.js and relevant less files in a follow-up. Thanks!

Resolves brave#9149

Auditors:

Test Plan:
@NejcZdovc NejcZdovc force-pushed the refactor/#9149-computed branch from 2c1c1be to e2df69a Compare June 16, 2017 08:13
@NejcZdovc NejcZdovc merged commit f1b2bb8 into brave:master Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants